package com.zcx.base.log.aspect;

import com.zcx.base.log.local.LogThreadLocal;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.slf4j.MDC;
import org.springframework.stereotype.Component;
import java.util.UUID;


/**
 *
 * 后期可以改为拦截批量job的方法
 *
 * http使用filter实现
 */
@Slf4j
@Component
@Aspect
public class TraceIdHandler {

    private static final String TRACE_ID = "traceId";

    /*@Before(value = "execution(* com.zcx.base..*(..))")
    public void aroundHandle() {
        //String traceId = LogThreadLocal.getTraceId();
        System.out.println("eeeeee");
        if (StringUtils.isBlank(MDC.get(TRACE_ID))) {
            UUID uuid = UUID.randomUUID();
            String uniqueId = TRACE_ID +"-"+ uuid.toString().replace("-", "");
            MDC.put(TRACE_ID, uniqueId);
        }
    }*/


    @Before(value = "execution(* com.zcx.base..*(..))")
    public void aroundHandle() {
        //if (StringUtils.isEmpty(MDC.get(TRACE_ID))) {
        //    MDC.put(TRACE_ID, LogThreadLocal.getTraceId());
        //}
    }
}
